<template>
    <div class="box">
      <video src="@/assets/video/aa.mp4" loop autoplay muted></video>
      <div class="container">
      <h1>千锋管理系统</h1>
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户名" prop="username">
    <el-input  class="ps" type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input class="ps"   type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="验证码" prop="captcha">
    <el-input class="ps"  v-model.number="ruleForm.captcha"  type="text"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>
    </div>

    </div>
</template>
    
<script>

    //校验验证码
    var validataCaptcha = (rule, value, callback) => {
      
      };
      //校验用户名
      var validataUsername = (rule, value, callback) => {
        // console.log(rule)
        // console.log(value)
        //3-16字母数字下划线
        var uPattern = /^[a-zA-Z0-9_-] {3,16}$ /;

        //如果校验通过，要直接回调函数callback（）
        //如果校验不通过  callback中传参数

        if(uPattern.test( value)){
          callback()
        }else{
             callback("3-16字母数字下划线")
        }
      };
      //校验密码
      var validatePassward = (rule, value, callback) => {
              if(value){
                  callback()

              }else{
                   callback("请输入密码   ")
              }



      };
  export default {
    data() {
  
      return {
        ruleForm: {
          username: '',
          password: '',
          captcha: ''
        },
        rules: {
          username: [
            { validator: validataUsername, trigger: 'blur' }
          ],
          password: [
            { validator: validatePassward, trigger: 'blur' }
          ],
          captcha: [
            { validator: validataCaptcha, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style lang="less" scoped> 


.ps {
   /deep/ .el-input__inner{   
         width:200px
    }
}
.container{
   width: 300px;
   height: 450px;
   border: 1px ;
   justify-content: center;
 
   margin-top: 50px;
   text-align: center;

    position: fixed;
  top: 0;
  margin: 0;
  right: 0;
  left:0;
}

h1{

   margin-top: 40px;
   margin-left:30px;
  justify-content: center;
  color:rgb(204, 210, 216);
}
.box{
  position: fixed;
  top: 0;
  margin: 0;
  right: 0;
  left:0;
}

</style>